﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class AddDor : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.lblImg.Text = "支持.png格式";
    }

    protected void TxtID_TextChanged(object sender, EventArgs e)
    {
        string sql = string.Format("select * from Doctor where ID='{0}'", this.TxtID.Text);
        int n = Convert.ToInt32(DBHelper.GetScalar(sql));
        if (n != 0)
        {
            lblTs.Text = "医生编号已存在。";
        }
        else
        {
            lblTs.Text = "";
        }
    }

    protected void BtnTj_Click(object sender, EventArgs e)
    {
        string sql = string.Format("select count(*) from Doctor where ID='{0}'", this.TxtID.Text);
        int n= Convert.ToInt32(DBHelper.GetScalar(sql));
        string sex = "";
        string Demt = this.DropDemt.SelectedValue;
        if (this.Sex1.Checked == true)
        {
            sex = "男";
        }
        if (this.Sex2.Checked == true)
        {
            sex = "女";
        }
        if (n == 0)
        {
            if (this.TxtID.Text != "" && this.TxtName.Text != "" && this.TxtIDCrad.Text != "" && this.Txtpsd.Text != "")
            {
                string insertsql = string.Format("insert into Doctor (ID,Name,PassWord,IDCard,Sex,Department,Position,Phone,Address,Introduction) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')", this.TxtID.Text, this.TxtName.Text, this.Txtpsd.Text, this.TxtIDCrad.Text, sex, Demt, this.Position.Text, this.Phone.Text, this.Address.Text, this.Introduction.Text);
                DBHelper.GetNonQuery(insertsql);
                this.image.SaveAs(Server.MapPath("~/image/Photo/") + this.image.FileName);
                Response.Write("<script> alert('添加成功!') </script>");
                this.TxtID.Text = "";
                this.TxtIDCrad.Text = "";
                this.TxtName.Text = "";
                this.Txtpsd.Text = "";
                this.Position.Text = "";
                this.Phone.Text = "";
                this.Address.Text = "";
                this.Introduction.Text = "";
            }
            else
            {
                Response.Write("<script> alert('添加失败,重要信息不能为空!') </script>");
            }
        }
        else
        {
            Response.Write("<script> alert('添加失败，请输入正确的医生信息!') </script>");
        }

    }

    protected void BtnQk_Click(object sender, EventArgs e)
    {
        this.TxtID.Text = "";
        this.TxtIDCrad.Text = "";
        this.TxtName.Text = "";
        this.Txtpsd.Text = "";
        this.Position.Text = "";
        this.Phone.Text = "";
        this.Address.Text = "";
        this.Introduction.Text = "";
    }
}